﻿@model equinoxWeb.Models.Facturacion
@{
    ViewBag.Title = "Detalle de costos";
    Layout = (ViewBag.esCliente!=null && ViewBag.esCliente?"~/Views/Shared/_ClienteLayout.cshtml":"~/Views/Shared/_Layout.cshtml");
}
@using equinoxWeb.Models;
<!-- content -->
<script type='text/javascript' src="/scripts/costDocument.js"></script>

<form class="form-horizontal" name="detailsForm" method="get">
    <fieldset>
        <legend>Detalle de costos</legend>
        @Html.HiddenFor(model => model.IdCaso, new { @class = "form-control" })
        @Html.HiddenFor(model => model.IdFacturacion, new { @class = "form-control" })
        <input type="hidden" name="idDocumento" value="@Model.IdFacturacion" />
        
        <div class="form-group">
            <label class="col-md-4 col-sm-6 control-label" for="Facturara">@(ViewBag.lang==null || ViewBag.lang == "ES" ? "Facturar a":"On behalf of"):</label>
            <div class="col-md-3 col-sm-6 form-control-static">
                @Model.Facturara
            </div>
        </div>

        <div class="form-group">
            <label class="col-md-4 col-sm-6 control-label" for="Rate">@(ViewBag.lang==null || ViewBag.lang == "ES" ? "Costo por hora":"Hourly rate"):</label>
            <div class="col-md-3 col-sm-6 form-control-static">
                @Model.Rate
            </div>
        </div>

        <div class="form-group">
            <label class="col-md-4 col-sm-6 control-label" for="Expenses">@(ViewBag.lang==null || ViewBag.lang == "ES" ? "Gastos":"Expenses"):</label>
            <div class="col-md-3 col-sm-6 form-control-static">
                @Model.Expenses
            </div>
        </div>

        <div class="form-group">
            <label class="col-md-4 col-sm-6 control-label" for="Moneda">@(ViewBag.lang==null || ViewBag.lang == "ES" ? "Moneda":"Currency"):</label>
            <div class="col-md-3 col-sm-6 form-control-static">
                @foreach (Moneda moneda in ViewBag.listaMoneda)
                {
                    if (moneda.IdMoneda == Model.IdMoneda)
                    {
                    @moneda.Nombre
                        break;
                    }
                }
            </div>
        </div>
        <div class="form-group">
            <label class="col-md-4 col-sm-6 control-label"></label>
            <div class="col-md-3 col-sm-6">
            </div>
        </div>
        <fieldset>
            <legend>@(ViewBag.lang==null || ViewBag.lang == "ES" ? "Costos de viaje":"Travelling costs"):</legend>
        </fieldset>

        <table id="tablaCostosTravelling" class="table table-hover">
            <tr>
                <th>@(ViewBag.lang==null || ViewBag.lang == "ES" ? "Fecha":"Date")</th>
                <th>@(ViewBag.lang==null || ViewBag.lang == "ES" ? "Desde":"From")</th>
                <th>@(ViewBag.lang==null || ViewBag.lang == "ES" ? "Hasta":"To")</th>
                <th>@(ViewBag.lang==null || ViewBag.lang == "ES" ? "Horas":"Hours")</th>
                <th style="width: 30%">@(ViewBag.lang==null || ViewBag.lang == "ES" ? "Descripcion":"Concept")</th>
                <th>Surveyor</th>
                <th>Subtotal</th>
            </tr>
            @for (int i = 0; i < Model.DetallesFacturacion.ToArray().Length; i++)
            {
                DetalleFacturacion detalle = Model.DetallesFacturacion.ElementAt(i);
                if (detalle.TipoCosto == Constantes.TipoCostoTravelling)
                {
                    <tr>
                        <td>
                        @detalle.Fecha
                        <td>
                        @detalle.HoraIni
                        <td>
                        @detalle.HoraFin
                        <td>
                        @detalle.HorasSubtotales
                        <td>
                        @detalle.Descripcion
                        <td>
                        @detalle.Surveyor
                        <td>
                            @detalle.Costo
                        </td>
                    </tr>
                }

            }

        </table>
        
        <div class="form-group">
            <label class="col-md-4 col-sm-6 control-label"></label>
            <div class="col-md-3 col-sm-6">
            </div>
        </div>
        <fieldset>
            <legend>@(ViewBag.lang==null || ViewBag.lang == "ES" ? "Costos de espera":"Waiting costs"):</legend>
        </fieldset>

        <table id="tablaCostosWaiting" class="table table-hover">
            <tr>
                <th>@(ViewBag.lang==null || ViewBag.lang == "ES" ? "Fecha":"Date")</th>
                <th>@(ViewBag.lang==null || ViewBag.lang == "ES" ? "Desde":"From")</th>
                <th>@(ViewBag.lang==null || ViewBag.lang == "ES" ? "Hasta":"To")</th>
                <th>@(ViewBag.lang==null || ViewBag.lang == "ES" ? "Horas":"Hours")</th>
                <th style="width: 30%">@(ViewBag.lang==null || ViewBag.lang == "ES" ? "Descripcion":"Concept")</th>
                <th>Surveyor</th>
                <th>Subtotal</th>
            </tr>
            @for (int i = 0; i < Model.DetallesFacturacion.ToArray().Length; i++)
            {
                DetalleFacturacion detalle = Model.DetallesFacturacion.ElementAt(i);
                if (detalle.TipoCosto == Constantes.TipoCostoWaiting)
                {
                    <tr>
                        <td>
                        @detalle.Fecha
                        <td>
                        @detalle.HoraIni
                        <td>
                        @detalle.HoraFin
                        <td>
                        @detalle.HorasSubtotales
                        <td>
                        @detalle.Descripcion
                        <td>
                        @detalle.Surveyor
                        <td>
                            @detalle.Costo
                        </td>
                    </tr>
                }

            }

        </table>
        <div class="form-group">
            <label class="col-md-4 col-sm-6 control-label"></label>
            <div class="col-md-3 col-sm-6">
            </div>
        </div>
        <fieldset>
            <legend>@(ViewBag.lang==null || ViewBag.lang == "ES" ? "Costos de trabajo":"Working costs"):</legend>
        </fieldset>

        <table id="tablaCostosWorking" class="table table-hover">
            <tr>
                <th>@(ViewBag.lang==null || ViewBag.lang == "ES" ? "Fecha":"Date")</th>
                <th>@(ViewBag.lang==null || ViewBag.lang == "ES" ? "Desde":"From")</th>
                <th>@(ViewBag.lang==null || ViewBag.lang == "ES" ? "Hasta":"To")</th>
                <th>@(ViewBag.lang==null || ViewBag.lang == "ES" ? "Horas":"Hours")</th>
                <th style="width: 30%">@(ViewBag.lang==null || ViewBag.lang == "ES" ? "Descripcion":"Concept")</th>
                <th>Surveyor</th>
                <th>Subtotal</th>
            </tr>
            @for (int i = 0; i < Model.DetallesFacturacion.ToArray().Length; i++)
            {
                DetalleFacturacion detalle = Model.DetallesFacturacion.ElementAt(i);
                if (detalle.TipoCosto == Constantes.TipoCostoWorking)
                {
                    <tr>
                        <td>
                        @detalle.Fecha
                        <td>
                        @detalle.HoraIni
                        <td>
                        @detalle.HoraFin
                        <td>
                        @detalle.HorasSubtotales
                        <td>
                        @detalle.Descripcion
                        <td>
                        @detalle.Surveyor
                        <td>
                            @detalle.Costo
                        </td>
                    </tr>
                }

            }

        </table>

        <div class="form-group">
        </div>
        <div class="form-group">
        </div>
        <div class="form-group">
                <button type="button" class="btn btn-large btn-primary" onclick="javascript:ExportInvoiceCostDocument(document.detailsForm)">@(ViewBag.lang==null || ViewBag.lang == "ES" ? "Exportar Invoice":"Invoice pdf")</button>&nbsp;
                <button type="button" class="btn btn-large btn-primary" onclick="javascript:ExportWSCostDocument(document.detailsForm)">@(ViewBag.lang==null || ViewBag.lang == "ES" ? "Exportar Working Sheet":"Working sheet pdf")</button>&nbsp;
                @if (!ViewBag.esCliente){
                    <button type="button" class="btn btn-large btn-primary" onclick="javascript:EditCostDocument(document.detailsForm)">Editar</button> 
                }
            <button type="button" class="btn btn-large" onclick="javascript:abrirCaso()">@(ViewBag.lang==null || ViewBag.lang == "ES" ? "Atras":"Back")</button>
        </div>


    </fieldset>
</form>
<script>
    function abrirCaso() {
        detailsForm.action = "/caso/details";
        detailsForm.submit();
    }
</script>
<!-- / content -->
